package linklist;

public class L19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dumyhead = new ListNode(0);
        dumyhead.next=head;
        ListNode fastNode=dumyhead;
        ListNode slowNode=dumyhead;
        int i=0;
        while (i<=n){
            fastNode=fastNode.next;
            i++;
        }
        while (fastNode!=null){//这里不能是next
            fastNode=fastNode.next;
            slowNode=slowNode.next;
        }
        if (slowNode.next!=null){
            slowNode.next=slowNode.next.next;
        }

        return dumyhead.next;
    }

}
